using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ShivamEMR.Model.Domain.CompanyDomain;
using ShivamEMR.Model.DataInterfaces.CompanyDataInterf;
using ShivamEMR.Model;
using ShivamEMR.Web.Models;
//using ShivamEMR.Web.Areas.Company.Models;

namespace ShivamEMR.Web.Areas.Company.Controllers
{   
    public class EmployeeGroupController : Controller
    {
		private readonly IEmployeeGroupRepository employeegroupRepository;

		// If you are using Dependency Injection, you can delete the following constructor
        public EmployeeGroupController() 
        {
            employeegroupRepository = Registry.RepositoryFactory.GetEmployeeGroupRepository();
        }

        public EmployeeGroupController(IEmployeeGroupRepository employeegroupRepository)
        {
			this.employeegroupRepository = employeegroupRepository;
        }

        //
        // GET: /EmployeeGroup/
        [CustomAuthorizeAttribute(RequiredRight = "Admin")]
        public ViewResult Index()
        {
          //  return View(employeegroupRepository.AllIncluding(employeegroup => employeegroup.Parent, employeegroup => employeegroup.Children, employeegroup => employeegroup.Employees));
            return View(employeegroupRepository.All);
        }

        //
        // GET: /EmployeeGroup/Details/5
        [CustomAuthorizeAttribute(RequiredRight = "Admin")]
        public ViewResult Details(int id)
        {
            return View(employeegroupRepository.Find(id));
        }

        //
        // GET: /EmployeeGroup/Create
        [CustomAuthorizeAttribute(RequiredRight = "Admin")]
        public ActionResult Create()
        {
			ViewBag.PossibleParents = employeegroupRepository.All;
            return View();
        } 

        //
        // POST: /EmployeeGroup/Create
        [CustomAuthorizeAttribute(RequiredRight = "Admin")]
        [HttpPost]
        public ActionResult Create(EmployeeGroup employeegroup)
        {
            if (ModelState.IsValid) {
                employeegroupRepository.Create(employeegroup);
                employeegroupRepository.Save();
                return RedirectToAction("Index");
            } else {
				ViewBag.PossibleParents = employeegroupRepository.All;
				return View();
			}
        }
        
        //
        // GET: /EmployeeGroup/Edit/5
 [CustomAuthorizeAttribute(RequiredRight = "Admin")]
        public ActionResult Edit(int id)
        {
			ViewBag.PossibleParents = employeegroupRepository.All;
             return View(employeegroupRepository.Find(id));
        }

        //
        // POST: /EmployeeGroup/Edit/5
        [CustomAuthorizeAttribute(RequiredRight = "Admin")]
        [HttpPost]
        public ActionResult Edit(EmployeeGroup employeegroup)
        {
            if (ModelState.IsValid) {
                employeegroupRepository.Update(employeegroup);
                employeegroupRepository.Save();
                return RedirectToAction("Index");
            } else {
				ViewBag.PossibleParents = employeegroupRepository.All;
				return View();
			}
        }

        //
        // GET: /EmployeeGroup/Delete/5
 [CustomAuthorizeAttribute(RequiredRight = "Admin")]
        public ActionResult Delete(int id)
        {
            return View(employeegroupRepository.Find(id));
        }

        //
        // POST: /EmployeeGroup/Delete/5
        [CustomAuthorizeAttribute(RequiredRight = "Admin")]
        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            //employeegroupRepository.Delete(id);
            var empgroup = employeegroupRepository.Find(id);
             employeegroupRepository.Delete(empgroup);
            employeegroupRepository.Save();

            return RedirectToAction("Index");
        }
    }
}

